package com.dt76.smallloanbackendservice.controller.lhuaw;


import com.dt76.smallloanbackendservice.pojo.lhuaw.StationLetter;
import com.dt76.smallloanbackendservice.service.lhuaw.StationLetterService;
import com.dt76.smallloanbackendservice.utils.Page;
import com.dt76.smallloanbackendservice.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/lhuaw")
public class StationLetterController {
    @Resource
    private StationLetterService stationLetterService;

    @RequestMapping("/qryAll")
    @ResponseBody
    public List<StationLetter> StationLetter1(){
        return stationLetterService.qryAll();
    }

    @RequestMapping("/getConditionPageAll")
    @ResponseBody
    public Page qryStationConditionPageAll(@RequestParam("pageIndex")  int pageIndex,
                                           @RequestParam("stationMessageTitle") String stationMessageTitle,
                                           @RequestParam("stationPublisher") String stationPublisher){
        System.out.println("成功调用远程");
        return stationLetterService.getAllStationLetter(pageIndex, stationMessageTitle, stationPublisher);
    }
//删除
@RequestMapping("/delStation")
@ResponseBody
public Result delStation(@RequestParam("stationId")int stationId){
    System.out.println("成功调用删除方法，正在执行StationLetterController.delStation>>>>>>>>");
    try {
        stationLetterService.deleteStation(stationId);
        return new Result(true,"删除成功>>>");
    } catch (Exception e) {
        return new Result(false,"删除失败>>>");
    }
}
    //新增
    @RequestMapping("/addStation")
    @ResponseBody
    public Result addStation(@RequestBody StationLetter stationLetter){
        System.out.println("成功调用远程服务:正在执行StationLetterService>addStation>>>");
        //调用新增接口
        try {
            stationLetterService.addStation(stationLetter);
            return new Result(true,"新增成功>>>");
        } catch (Exception e) {
            return new Result(false,"新增失败>>>");
        }
    }
    //查看
    @RequestMapping("/seeStation")
    @ResponseBody
    public StationLetter seeStation(@RequestParam("stationId") int stationId){
        System.out.println("成功调用远程服务:StationLetterService>seeStation>>>");
        return stationLetterService.seeStation(stationId);
    }

}
